{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 10 if语句"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.【判断】if语句执行从上往下判断，如果在某个判断上是True，则执行该判断对应的语句，忽略剩下的elif和else（ ）\n",
    "\n",
    "A.√  \n",
    "B.×"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：A"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.【填空】下列代码的运行结果是：（ ）  \n",
    "`\n",
    "grade = 70\n",
    "level = \"pass\" if grade>60 else \"fail\"\n",
    "print(level)`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.【选择】下列关于Python中条件语句的用法错误的是：（ ）\n",
    "\n",
    "A.if 后复合语句采用缩进的方式，而不是{}  \n",
    "B.Python中使用elif，而不是else if  \n",
    "C.if可以写成一行表达式  \n",
    "D.if语句中可以有空语句"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：D"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.【选择】下面表达式中i的值是：（ ）  \n",
    "`i = 5 if 5>6 else (2 if 2>3 else 3)`\n",
    "\n",
    "A.2  \n",
    "B.3  \n",
    "C.5  \n",
    "D.6"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：B"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5.【选择】下列语句的运行结果是：（ ）  \n",
    "`\n",
    "x = 10\n",
    "y = 6\n",
    "z = 4\n",
    "if (x>y):\n",
    "    x,y = y,x\n",
    "if (x>z):\n",
    "    x,z = z,x\n",
    "print(x,y,z)`\n",
    "\n",
    "A.10 6 4  \n",
    "B.6 10 4  \n",
    "C.4 6 10  \n",
    "D.4 10 6"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：D"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "6.【改错】请把下列错误代码改正,并写出运行结果。  \n",
    "`\n",
    "i = \"a\"\n",
    "j = \"A\"\n",
    "if(i<j)\n",
    "    print(i)\n",
    "elsif(i>j):\n",
    "    print(j)\n",
    "else:\n",
    "print(\"i、j相等\")`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：  \n",
    "`\n",
    "i = \"a\"\n",
    "j = \"A\"\n",
    "if(i<j):\n",
    "    print(i)\n",
    "elif(i>j):\n",
    "    print(j)\n",
    "else:\n",
    "    print(\"i、j相等\")`\n",
    "\n",
    "A"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "7.【编程】根据下列条件编写一个公司绩效等级判断的程序。  \n",
    "用户输入一个0~100的绩效评分，若绩效分数小于60等级为D，分数大于等于60并小于70等级为C，分数大于等于70并小于85等级为B，分数大于等于85等级为A。若输入评分不符合规定则提示用户输入错误。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "参考答案：  \n",
    "`\n",
    "grade = int(input(\"请输入绩效评分\"))\n",
    "if(grade>=0 and grade<=100):\n",
    "    if(grade<60):\n",
    "        level = \"D\"\n",
    "    elif(grade<70):\n",
    "        level = \"C\"\n",
    "    elif(grade<85):\n",
    "        level = \"B\"\n",
    "    else:\n",
    "        level = \"A\"\n",
    "    print(\"绩效等级为：\",level)\n",
    "else:\n",
    "    print(\"绩效评分输入有误！\")`"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
